import gradio as gr
from transformers import pipeline

# Use a pipeline as a high-level helper
pipe = pipeline("text-classification", model="./chatgpt-detector-roberta-chinese")


def roberta_detect_ai_text(text):
    result = pipe(text)
    return result[0]["label"]


def detectgpt(text):
    return ""


def detect_ai_text(text):
    return detectgpt(text), roberta_detect_ai_text(text)


# 创建Gradio界面
interface = gr.Interface(
    fn=detect_ai_text,
    inputs=[gr.Textbox(label="文本内容")],
    outputs=[
        gr.Label(label="DetectGPT检测结果"),
        gr.Label(label="Roberta监督学习检测结果"),
    ],
    title="AI文本检测器",
    description="输入文本，检测是否可能为AI生成。",
)

# 启动界面
interface.launch()
